home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-11-08 | 41.4 KB | 1,267 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWView.cpp
- // Release Version: $ 1.0d10 $
- //
- // Copyright: © 1995 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "FWFrameW.hpp"
-
- #ifndef FWVIEW_H
- #include "FWView.h"
- #endif
-
- #ifndef FWFRAME_H
- #include "FWFrame.h"
- #endif
-
- #ifndef FWEVENT_H
- #include "FWEvent.h"
- #endif
-
- #ifndef FWSCROLR_H
- #include "FWScrolr.h"
- #endif
-
- #ifndef FWSELECT_H
- #include "FWSelect.h"
- #endif
-
- #ifndef FWPRESEN_H
- #include "FWPresen.h"
- #endif
-
- #ifndef FWODGEOM_H
- #include "FWODGeom.h"
- #endif
-
- #ifndef FWWINDOW_H
- #include "FWWindow.h"
- #endif
-
- #ifndef FWCURSOR_H
- #include "FWCursor.h"
- #endif
-
- #ifndef SOM_ODFrame_xh
- #include <Frame.xh>
- #endif
-
- #ifndef SOM_ODShape_xh
- #include <Shape.xh>
- #endif
-
- //========================================================================================
- // Runtime Informations
- //========================================================================================
-
- #if FW_LIB_EXPORT_PRAGMAS
- #pragma lib_export on
- #endif
-
- #ifdef FW_BUILD_MAC
- #pragma segment fwview
- #endif
-
- //========================================================================================
- // CLASS FW_CView
- //========================================================================================
-
- FW_DEFINE_CLASS_M1(FW_CView, FW_MEventHandler)
-
- //----------------------------------------------------------------------------------------
- // FW_CView::FW_CView
- //----------------------------------------------------------------------------------------
- FW_CView::FW_CView(Environment* ev, FW_CView* container,
- ODID theID, FW_Boolean enabled, FW_Priority thePriority,
- const FW_CRect& bounds, const FW_CPoint& extent,
- FW_CScroller* scroller,
- int contentSpace) :
- FW_MEventHandler(ev, theID, container, enabled, thePriority),
- fParentView(container),
- fSubViews(NULL),
- fBounds(bounds),
- fScroller(scroller),
- fAdorners(NULL),
- fVisible(TRUE),
- fIsContentView(FALSE),
- fViewContentToFrameTransform(NULL),
- fViewToFrameTransform(NULL),
- fViewContentToViewTransform(NULL),
- fContentSpaceSpecifier(contentSpace)
- {
- fExtent = (extent == FW_kZeroPoint) ? fBounds.Size() : extent;
-
- // add new view to the parent's SubView list
- fParentView->AddSubView(ev, this);
-
- // if view scrolls with content add it to the frame's list of scrolling views
- if (UseContentSpaceInX(ev) || UseContentSpaceInY(ev)) {
- GetFrame(ev)->AddScrollingView(ev, this);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CView::FW_CView
- //----------------------------------------------------------------------------------------
-
- FW_CView::FW_CView(Environment* ev, FW_CView* container, const FW_CRect& bounds, const FW_CPoint& extent,
- FW_CScroller* scroller, int contentSpace) :
- FW_MEventHandler(ev, 0, container, TRUE, kNoPriority),
- fParentView(container),
- fSubViews(NULL),
- fBounds(bounds),
- fScroller(scroller),
- fAdorners(NULL),
- fVisible(TRUE),
- fIsContentView(FALSE),
- fViewContentToFrameTransform(NULL),
- fViewToFrameTransform(NULL),
- fViewContentToViewTransform(NULL),
- fContentSpaceSpecifier(contentSpace)
- {
- fExtent = (extent == FW_kZeroPoint) ? fBounds.Size() : extent;
-
- // add new view to the parent's SubView list
- fParentView->AddSubView(ev, this);
-
- // if view scrolls with content add it to the frame's list of scrolling views
- if (UseContentSpaceInX(ev) || UseContentSpaceInY(ev)) {
- GetFrame(ev)->AddScrollingView(ev, this);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CView::FW_CView
- //----------------------------------------------------------------------------------------
-
- FW_CView::FW_CView(Environment* ev) :
- FW_MEventHandler(),
- fParentView(NULL),
- fSubViews(NULL),
- fScroller(NULL),
- fAdorners(NULL),
- fVisible(TRUE),
- fIsContentView(FALSE),
- fViewContentToFrameTransform(NULL),
- fViewToFrameTransform(NULL),
- fViewContentToViewTransform(NULL),
- fContentSpaceSpecifier(0)
- {
- // this ctor should be used by CFrame only, the only CView with a NULL fParentView
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CView::~FW_CView
- //----------------------------------------------------------------------------------------
-
- FW_CView::~FW_CView()
- {
- Environment *ev = somGetGlobalEnvironment();
-
- if (fScroller) {
- delete fScroller;
- fScroller = NULL;
- }
-
- if (fSubViews)
- {
- FW_CView* view;
- while ((view = (FW_CView*)fSubViews->Last()) != NULL) {
- delete view; // deleting a view remove itself from its parentView
- }
- delete fSubViews;
- fSubViews = NULL;
- }
-
- if (fViewContentToFrameTransform) {
- fViewContentToFrameTransform->Release(ev);
- fViewContentToFrameTransform = NULL;
- }
-
- if (fViewToFrameTransform) {
- fViewToFrameTransform->Release(ev);
- fViewToFrameTransform = NULL;
- }
-
- if (fViewContentToViewTransform) {
- fViewContentToViewTransform->Release(ev);
- fViewContentToViewTransform = NULL;
- }
-
- // *LSD: fAdorners?
-
- if (fParentView != NULL)
- fParentView->RemoveSubView(ev, this);
-
- if (UseContentSpaceInX(ev) || UseContentSpaceInY(ev)) {
- GetFrame(ev)->RemoveScrollingView(ev, this);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CView::SetExtent
- //----------------------------------------------------------------------------------------
-
- void FW_CView::SetExtent(Environment* ev, const FW_CPoint& extent)
- {
- fExtent = extent;
-
- // ContentView must udpate the ODFrame's extent
- if (fIsContentView) {
- ODPoint odPoint = extent;
- GetFrame(ev)->GetODFrame(ev)->ChangeContentExtent(ev, &odPoint);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CView::MakeContentView
- //----------------------------------------------------------------------------------------
-
- void FW_CView::MakeContentView(Environment* ev)
- {
- FW_CFrame* frame = GetFrame(ev);
-
- // Declare ContentView to the CFrame
- frame->SetContentView(ev, this);
- fIsContentView = TRUE;
-
- // Set the extent to the ODFrame's extent, or the view's bounds
- ODPoint odPoint;
- frame->GetODFrame(ev)->GetContentExtent(ev, &odPoint);
- if (odPoint.x == 0 && odPoint.y == 0)
- fExtent = fBounds.Size();
- else
- fExtent = odPoint;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CView::AddSubView
- //----------------------------------------------------------------------------------------
-
- void FW_CView::AddSubView(Environment* ev, const FW_CView *subview)
- {
- if (fSubViews == NULL) {
- fSubViews = new FW_CPrivOrderedCollection;
- }
- else {
- FW_ASSERT(fSubViews->Contains(this) == FALSE); // [LSD] should have an Assert here?
- }
-
- fSubViews->AddLast((FW_CView*) subview);
- SubViewAdded(ev, subview);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CView::SubViewAdded
- //----------------------------------------------------------------------------------------
-
- void FW_CView::SubViewAdded(Environment* ev, const FW_CView* subview)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CView::RemoveSubView
- //----------------------------------------------------------------------------------------
-
- void FW_CView::RemoveSubView(Environment* ev, const FW_CView* subview)
- {
- FW_ASSERT(fSubViews != NULL);
- FW_ASSERT(fSubViews->Contains((FW_CView*)subview));
-
- fSubViews->Remove((FW_CView*)subview);
- SubViewRemoved(ev, subview);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CView::SubViewRemoved
- //----------------------------------------------------------------------------------------
-
- void FW_CView::SubViewRemoved(Environment* ev, const FW_CView* subview)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CView::Invalidate
- //----------------------------------------------------------------------------------------
-
- void FW_CView::Invalidate(Environment* ev, const FW_CRect& rect)
- {
- FW_CRect tempRect(rect);
- ViewContentToFrame(ev, tempRect);
- FW_CAcquiredODShape aqInvalidShape = ::FW_NewODShape(ev, tempRect);
- GetFrame(ev)->GetODFrame(ev)->Invalidate(ev, aqInvalidShape, NULL);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CView::Validate
- //----------------------------------------------------------------------------------------
-
- void FW_CView::Validate(Environment* ev, const FW_CRect& rect)
- {
- FW_CRect tempRect(rect);
- ViewContentToFrame(ev, tempRect);
- FW_CAcquiredODShape aqValidShape = ::FW_NewODShape(ev, tempRect);
- GetFrame(ev)->GetODFrame(ev)->Validate(ev, aqValidShape, NULL);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CView::Invalidate
- //----------------------------------------------------------------------------------------
-
- void FW_CView::Invalidate(Environment* ev, ODShape* invalidShape)
- {
- if (invalidShape == NULL)
- {
- FW_CRect bounds(FW_kZeroPoint, GetSize(ev));
- ViewToViewContent(ev, bounds);
- Invalidate(ev, bounds);
- }
- else
- {
- FW_CAcquiredODShape aqCopy = invalidShape->Copy(ev);
- ViewContentToFrame(ev, aqCopy);
- GetFrame(ev)->GetODFrame(ev)->Invalidate(ev, aqCopy, NULL);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CView::Validate
- //----------------------------------------------------------------------------------------
-
- void FW_CView::Validate(Environment* ev, ODShape* invalidShape)
- {
- if (invalidShape == NULL)
- {
- FW_CRect bounds(FW_kZeroPoint, GetSize(ev));
- ViewToViewContent(ev, bounds);
- Validate(ev, bounds);
- }
- else
- {
- FW_CAcquiredODShape aqCopy = invalidShape->Copy(ev);
- ViewContentToFrame(ev, aqCopy);
- GetFrame(ev)->GetODFrame(ev)->Validate(ev, aqCopy, NULL);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CView::AdjustCursor
- //----------------------------------------------------------------------------------------
- // where is in frame coordinate
-
- FW_Boolean FW_CView::AdjustCursor(Environment *ev, ODFacet* odFacet, const FW_CPoint& theMousePoint)
- {
- // If I am the content view let the frame do the job first
- if (fIsContentView) return GetFrame(ev)->AdjustCursor(ev, odFacet, theMousePoint);
-
- return FALSE;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CView::CountSubViews
- //----------------------------------------------------------------------------------------
-
- unsigned long FW_CView::CountSubViews(Environment* ev) const
- {
- return fSubViews == NULL ? 0 : fSubViews->Count();
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CView::IsSubViewOf
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_CView::IsSubViewOf(Environment* ev, const FW_CView &parentView) const
- {
- return (fParentView->fSubViews == NULL ? FALSE : fParentView->fSubViews->Contains((FW_CView*)&this));
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CView::IsMouseWithin
- //----------------------------------------------------------------------------------------
- // theMousePoint is in frame coordinate
-
- FW_Boolean FW_CView::IsMouseWithin(Environment* ev, ODFacet* odFacet, const FW_CPoint& theMousePoint) const
- {
- // We get a NULL facet when clicking outside a modal dialog box.
- if (odFacet == NULL)
- return FALSE;
-
- FW_CPoint where(theMousePoint);
- FrameToView(ev, where);
-
- return FW_CRect(FW_kZeroPoint, GetSize(ev)).Contains(where);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CView::CreateSubViews
- //----------------------------------------------------------------------------------------
-
- void FW_CView::CreateSubViews(Environment *ev)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CView::AdjustSubViews
- //----------------------------------------------------------------------------------------
-
- void FW_CView::AdjustSubViews(Environment *ev)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CView::GetViewContaining
- //----------------------------------------------------------------------------------------
- // Find the VISIBLE View containing a point (theMousePoint is in frame coordinate)
-
- FW_CView* FW_CView::GetViewContaining(Environment* ev,
- ODFacet* odFacet,
- const FW_CPoint& theMousePoint)
- {
- FW_CView* viewUnder = NULL;
-
- if (fVisible) {
- FW_CViewIterator ite(ev, this);
- for (FW_CView* subview = (FW_CView *) ite.First(ev);
- ite.IsNotComplete(ev) && !viewUnder;
- subview = (FW_CView *) ite.Next(ev))
- {
- viewUnder = subview->GetViewContaining(ev, odFacet, theMousePoint);
- }
-
- if (viewUnder == NULL)
- {
- if (IsMouseWithin(ev, odFacet, theMousePoint))
- viewUnder = this;
- }
- }
- return viewUnder;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CView::PrivGetEventHandlerContaining
- //----------------------------------------------------------------------------------------
- // theMousePoint is in frame coordinate
-
- FW_MEventHandler* FW_CView::PrivGetEventHandlerContaining(Environment* ev,
- ODFacet* odFacet,
- const FW_CPoint& theMousePoint)
- {
- return GetViewContaining(ev, odFacet, theMousePoint);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CView::AddScrollBarScroller
- //----------------------------------------------------------------------------------------
-
- void FW_CView::AddScrollBarScroller(Environment* ev, FW_CScrollBar* horzSB,
- FW_CScrollBar* vertSB)
- {
- if (fScroller) {
- delete fScroller;
- fScroller = NULL;
- }
-
- // create scroller
- FW_CScroller* scroller = new FW_CScrollBarScroller(ev, this, horzSB, vertSB);
- fScroller = scroller;
- scroller->UpdateScrollParameters(ev, FALSE); // We don't want to notify
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CView::SetLocation
- //----------------------------------------------------------------------------------------
-
- void FW_CView::SetLocation(Environment* ev, const FW_CPoint& location)
- {
- FW_CPoint oldLocation = fBounds.TopLeft();
-
- if (oldLocation != location)
- {
- fBounds.right = location.x + (fBounds.right - fBounds.left);
- fBounds.bottom = location.y + (fBounds.bottom - fBounds.top);
- fBounds.left = location.x;
- fBounds.top = location.y;
-
- PrivInvalidateCachedTransforms(ev);
-
- // must offset the frame's internal transform when ContentView is moved
- if (fIsContentView)
- {
- FW_CAcquiredODTransform aqTransform = GetFrame(ev)->AcquireInternalTransform(ev, NULL);
- ODPoint offset(location - oldLocation);
- aqTransform->MoveBy(ev, &offset);
- GetFrame(ev)->ChangeInternalTransform(ev, aqTransform);
-
- GetFrame(ev)->PrivContentViewLocationChanged(ev);
- }
-
- LocationChanged(ev, oldLocation); // used by gadgets on Windows
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CView::LocationChanged
- //----------------------------------------------------------------------------------------
-
- void FW_CView::LocationChanged(Environment* ev, const FW_CPoint& oldLocation)
- {
- FW_UNUSED(oldLocation);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CView::SetSize
- //----------------------------------------------------------------------------------------
-
- void FW_CView::SetSize(Environment* ev, const FW_CPoint& size)
- {
- FW_CPoint oldSize = fBounds.Size();
- if (oldSize != size) {
- fBounds.right = fBounds.left + size.x;
- fBounds.bottom = fBounds.top + size.y;
- SizeChanged(ev, oldSize); // used by gadgets on Windows
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CView::SizeChanged
- //----------------------------------------------------------------------------------------
-
- void FW_CView::SizeChanged(Environment* ev, const FW_CPoint& oldSize)
- {
- FW_UNUSED(oldSize);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CView::IsVisible
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_CView::IsVisible(Environment* ev) const
- {
- // If my parent is not visible I am also not visible
- return fVisible && (fParentView != NULL ? fParentView->IsVisible(ev) : TRUE);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CView::PrivInvalidateCachedTransforms
- //----------------------------------------------------------------------------------------
-
- void FW_CView::PrivInvalidateCachedTransforms(Environment* ev)
- {
- FW_CViewIterator iter(ev, this);
- for (FW_CView* subview = (FW_CView*)iter.First(ev); iter.IsNotComplete(ev); subview = (FW_CView*)iter.Next(ev))
- {
- subview->PrivInvalidateCachedTransforms(ev);
- }
-
- if (fViewContentToFrameTransform)
- {
- fViewContentToFrameTransform->Release(ev);
- fViewContentToFrameTransform = NULL;
- }
-
- if (fViewToFrameTransform)
- {
- fViewToFrameTransform->Release(ev);
- fViewToFrameTransform = NULL;
- }
-
- if (fViewContentToViewTransform)
- {
- fViewContentToViewTransform->Release(ev);
- fViewContentToViewTransform = NULL;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CView::IsInContentView
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_CView::IsInContentView(Environment* ev) const
- {
- if (fIsContentView)
- return TRUE;
- else if (IsFrame(ev))
- return FALSE; // this is the CFrame but its fIsContentView was FALSE
- else
- return fParentView->IsInContentView(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CView::AcquireViewContentToViewTransform
- //----------------------------------------------------------------------------------------
- // returns the transform to convert view content coordinates to view coordinates
-
- ODTransform* FW_CView::AcquireViewContentToViewTransform(Environment* ev) const
- {
- FW_CView* self = (FW_CView*)this;
-
- if (fViewContentToViewTransform == NULL)
- {
- self->fViewContentToViewTransform = FW_CopyAndRelease(ev, AcquireViewContentToFrameTransform(ev));
- FW_CAcquiredODTransform aqTransform = FW_CopyAndRelease(ev, AcquireViewToFrameTransform(ev));
- aqTransform->Invert(ev);
- self->fViewContentToViewTransform->PostCompose(ev, aqTransform);
- }
-
- self->fViewContentToViewTransform->Acquire(ev);
- return fViewContentToViewTransform;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CView::AcquireViewToFrameTransform
- //----------------------------------------------------------------------------------------
- // returns the transform to convert view coordinates to frame coordinates
-
- ODTransform* FW_CView::AcquireViewToFrameTransform(Environment* ev) const
- {
- FW_CView* self = (FW_CView*)this;
-
- if (fViewToFrameTransform == NULL)
- {
- FW_CPoint location = GetLocation(ev);
- self->fViewToFrameTransform = ::FW_NewODTransform(ev, location);
-
- if (fParentView != NULL)
- {
- FW_CAcquiredODTransform aqViewContentTransform = fParentView->AcquireViewContentToFrameTransform(ev);
- self->fViewToFrameTransform->PostCompose(ev, aqViewContentTransform);
- }
- }
-
- self->fViewToFrameTransform->Acquire(ev);
- return fViewToFrameTransform;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CView::AcquireViewContentToFrameTransform
- //----------------------------------------------------------------------------------------
- // returns the transform to convert view content coordinates to frame coordinates
-
- ODTransform* FW_CView::AcquireViewContentToFrameTransform(Environment* ev) const
- {
- FW_CView* self = (FW_CView*)this;
-
- if (fViewContentToFrameTransform == NULL)
- {
- self->fViewContentToFrameTransform = FW_CopyAndRelease(ev, AcquireViewToFrameTransform(ev));
-
- if (IsContentView(ev) || UseContentSpaceInX(ev) || UseContentSpaceInY(ev))
- {
- ODPoint offset, internalOffset;
- FW_CAcquiredODTransform aqInternalTransform = GetFrame(ev)->AcquireInternalTransform(ev, NULL);
- aqInternalTransform->GetOffset(ev, &internalOffset);
-
- // ----- the location of the content view is already included in the Internal transform -----
- FW_CPoint location = FW_kZeroPoint;
- GetFrame(ev)->GetContentView(ev)->ViewToFrame(ev, location); // gives me the location of the content view in frame coordinate
-
- // [LSD] need to handle scaling too
- offset.x = (UseContentSpaceInX(ev) || IsContentView(ev)) ? internalOffset.x - location.x.AsODFixed() : 0;
- offset.y = (UseContentSpaceInY(ev) || IsContentView(ev)) ? internalOffset.y - location.y.AsODFixed() : 0;
-
- self->fViewContentToFrameTransform->MoveBy(ev, &offset);
- }
- }
-
- self->fViewContentToFrameTransform->Acquire(ev);
-
- return fViewContentToFrameTransform;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CView::FrameToViewContent
- //----------------------------------------------------------------------------------------
-
- void FW_CView::FrameToViewContent(Environment *ev, FW_CPoint& point) const
- {
- FW_CAcquiredODTransform aqViewToFrameTransform(AcquireViewContentToFrameTransform(ev));
- point.InverseTransform(ev, aqViewToFrameTransform);
- }
-
- void FW_CView::FrameToViewContent(Environment *ev, FW_CRect& rect) const
- {
- FW_CAcquiredODTransform aqViewToFrameTransform(AcquireViewContentToFrameTransform(ev));
- rect.InverseTransform(ev, aqViewToFrameTransform);
- }
-
- void FW_CView::FrameToViewContent(Environment *ev, ODShape* shape) const
- {
- FW_CAcquiredODTransform aqViewToFrameTransform(AcquireViewContentToFrameTransform(ev));
- shape->InverseTransform(ev, aqViewToFrameTransform);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CView::ViewContentToFrame
- //----------------------------------------------------------------------------------------
-
- void FW_CView::ViewContentToFrame(Environment *ev, FW_CPoint& point) const
- {
- FW_CAcquiredODTransform aqViewToFrameTransform(AcquireViewContentToFrameTransform(ev));
- point.Transform(ev, aqViewToFrameTransform);
- }
-
- void FW_CView::ViewContentToFrame(Environment *ev, FW_CRect& rect) const
- {
- FW_CAcquiredODTransform aqViewToFrameTransform(AcquireViewContentToFrameTransform(ev));
- rect.Transform(ev, aqViewToFrameTransform);
- }
-
- void FW_CView::ViewContentToFrame(Environment *ev, ODShape* shape) const
- {
- FW_CAcquiredODTransform aqViewToFrameTransform(AcquireViewContentToFrameTransform(ev));
- shape->Transform(ev, aqViewToFrameTransform);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CView::FrameToView
- //----------------------------------------------------------------------------------------
-
- void FW_CView::FrameToView(Environment *ev, FW_CPoint& point) const
- {
- FW_CAcquiredODTransform aqViewToFrameTransform(AcquireViewToFrameTransform(ev));
- point.InverseTransform(ev, aqViewToFrameTransform);
- }
-
- void FW_CView::FrameToView(Environment *ev, FW_CRect& rect) const
- {
- FW_CAcquiredODTransform aqViewToFrameTransform(AcquireViewToFrameTransform(ev));
- rect.InverseTransform(ev, aqViewToFrameTransform);
- }
-
- void FW_CView::FrameToView(Environment *ev, ODShape* shape) const
- {
- FW_CAcquiredODTransform aqViewToFrameTransform(AcquireViewToFrameTransform(ev));
- shape->InverseTransform(ev, aqViewToFrameTransform);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CView::ViewToFrame
- //----------------------------------------------------------------------------------------
-
- void FW_CView::ViewToFrame(Environment *ev, FW_CPoint& point) const
- {
- FW_CAcquiredODTransform aqViewToFrameTransform(AcquireViewToFrameTransform(ev));
- point.Transform(ev, aqViewToFrameTransform);
- }
-
- void FW_CView::ViewToFrame(Environment *ev, FW_CRect& rect) const
- {
- FW_CAcquiredODTransform aqViewToFrameTransform(AcquireViewToFrameTransform(ev));
- rect.Transform(ev, aqViewToFrameTransform);
- }
-
- void FW_CView::ViewToFrame(Environment *ev, ODShape* shape) const
- {
- FW_CAcquiredODTransform aqViewToFrameTransform(AcquireViewToFrameTransform(ev));
- shape->Transform(ev, aqViewToFrameTransform);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CView::ViewToViewContent
- //----------------------------------------------------------------------------------------
-
- void FW_CView::ViewToViewContent(Environment *ev, FW_CPoint& point) const
- {
- FW_CAcquiredODTransform aqViewContentToViewTransform(AcquireViewContentToViewTransform(ev));
- point.InverseTransform(ev, aqViewContentToViewTransform);
- }
-
- void FW_CView::ViewToViewContent(Environment *ev, FW_CRect& rect) const
- {
- FW_CAcquiredODTransform aqViewContentToViewTransform(AcquireViewContentToViewTransform(ev));
- rect.InverseTransform(ev, aqViewContentToViewTransform);
- }
-
- void FW_CView::ViewToViewContent(Environment *ev, ODShape* shape) const
- {
- FW_CAcquiredODTransform aqViewContentToViewTransform(AcquireViewContentToViewTransform(ev));
- shape->InverseTransform(ev, aqViewContentToViewTransform);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CView::ViewContentToView
- //----------------------------------------------------------------------------------------
-
- void FW_CView::ViewContentToView(Environment *ev, FW_CPoint& point) const
- {
- FW_CAcquiredODTransform aqViewContentToViewTransform(AcquireViewContentToViewTransform(ev));
- point.Transform(ev, aqViewContentToViewTransform);
- }
-
- void FW_CView::ViewContentToView(Environment *ev, FW_CRect& rect) const
- {
- FW_CAcquiredODTransform aqViewContentToViewTransform(AcquireViewContentToViewTransform(ev));
- rect.Transform(ev, aqViewContentToViewTransform);
- }
-
- void FW_CView::ViewContentToView(Environment *ev, ODShape* shape) const
- {
- FW_CAcquiredODTransform aqViewContentToViewTransform(AcquireViewContentToViewTransform(ev));
- shape->Transform(ev, aqViewContentToViewTransform);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CView::GetFrame
- //----------------------------------------------------------------------------------------
- FW_CFrame* FW_CView::GetFrame(Environment* ev) const
- {
- FW_CView* container = GetParentView(ev);
-
- // a null ParentView means that it's a CFrame
- return container ? container->GetFrame(ev) : (FW_CFrame*)this;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CView::SetContentSpaceInX
- //----------------------------------------------------------------------------------------
- void FW_CView::SetContentSpaceInX(Environment *ev, FW_Boolean bool)
- {
- fContentSpaceSpecifier &= ~FW_CView::kXaxis;
- if (bool) {
- fContentSpaceSpecifier |= FW_CView::kXaxis;
- GetFrame(ev)->AddScrollingView(ev, this);
- }
- else {
- GetFrame(ev)->RemoveScrollingView(ev, this);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CView::SetContentSpaceInY
- //----------------------------------------------------------------------------------------
- void FW_CView::SetContentSpaceInY(Environment *ev, FW_Boolean bool)
- {
- fContentSpaceSpecifier &= ~FW_CView::kYaxis;
- if (bool) {
- fContentSpaceSpecifier |= FW_CView::kYaxis;
- GetFrame(ev)->AddScrollingView(ev, this);
- }
- else {
- GetFrame(ev)->RemoveScrollingView(ev, this);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CView::SetContentSpaceInScale
- //----------------------------------------------------------------------------------------
- void FW_CView::SetContentSpaceInScale(Environment *ev, FW_Boolean bool)
- {
- fContentSpaceSpecifier &= ~FW_CView::kScale;
- if (bool) fContentSpaceSpecifier |= FW_CView::kScale;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CView::HandleSuspendResumeEvent
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_CView::HandleSuspendResumeEvent(Environment* ev, const FW_CSuspendResumeEvent& theSuspendResumeEvent)
- {
- FW_Boolean handled = FALSE;
- FW_CViewIterator ite(ev, this);
- for (FW_CView* view = (FW_CView *) ite.First(ev);
- ite.IsNotComplete(ev) && !handled;
- view = (FW_CView *) ite.Next(ev))
- {
- handled = view->HandleSuspendResumeEvent(ev, theSuspendResumeEvent);
- }
-
- return handled ? TRUE
- : FW_MEventHandler::HandleSuspendResumeEvent(ev, theSuspendResumeEvent);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CView::HandleActivateEvent
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_CView::HandleActivateEvent(Environment* ev, const FW_CActivateEvent& theActivateEvent)
- {
- FW_Boolean handled = FALSE;
- FW_CViewIterator ite(ev, this);
- for (FW_CView* view = (FW_CView *) ite.First(ev);
- ite.IsNotComplete(ev) && !handled;
- view = (FW_CView *) ite.Next(ev))
- {
- handled = view->HandleActivateEvent(ev, theActivateEvent);
- }
-
- return handled ? TRUE
- : FW_MEventHandler::HandleActivateEvent(ev, theActivateEvent);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CView::HandleMouseDown
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_CView::HandleMouseDown(Environment* ev, const FW_CMouseEvent& theMouseEvent)
- {
- FW_CFrame* frame = GetFrame(ev);
- FW_ASSERT(frame);
-
- FW_Boolean inActiveWindow = frame->GetWindow(ev)->IsActive(ev);
-
- FW_Boolean clickedInFrame = fIsContentView || !frame->IsRoot(ev);
- if (frame->PrivActiveWindowOnMouseDown(ev, theMouseEvent.GetFacet(ev), clickedInFrame))
- return TRUE;
-
- if (fIsContentView)
- {
- FW_CSelection* selection = frame->GetPresentation(ev)->GetSelection(ev);
- if (selection)
- selection->UpdateSelectionOnMouseDown(ev, theMouseEvent, NULL, FALSE, FALSE);
- }
-
- if (inActiveWindow)
- {
- if (this->IsEnabled(ev) && this->WantsToBeTarget(ev))
- this->BecomeTarget(ev);
-
- FW_MEventHandler::HandleMouseDown(ev, theMouseEvent);
- }
-
- return TRUE;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CView::HandleMouseDownInEmbeddedFrameBorder
- //----------------------------------------------------------------------------------------
- // Set the cursor to the closed hand
-
- FW_Boolean FW_CView::HandleMouseDownInEmbeddedFrameBorder(Environment* ev, const FW_CBorderMouseEvent& theBorderMouseEvent)
- {
- FW_CFrame* frame = GetFrame(ev);
- FW_ASSERT(frame);
-
- FW_gClosedHandCursor.Select();
-
- frame->ActivateFrame(ev, theBorderMouseEvent.GetFacet(ev));
-
- FW_CSelection* selection = frame->GetPresentation(ev)->GetSelection(ev);
- if (selection)
- selection->UpdateSelectionOnMouseDown(ev,
- theBorderMouseEvent,
- theBorderMouseEvent.GetEmbeddedFacet(ev),
- TRUE,
- FALSE);
-
- return FW_MEventHandler::HandleMouseDownInEmbeddedFrameBorder(ev, theBorderMouseEvent);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CView::HandleMouseDownInEmbeddedFrame
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_CView::HandleMouseDownInEmbeddedFrame(Environment* ev,
- const FW_CEmbeddedMouseEvent& theEmbeddedMouseEvent)
- {
- FW_CFrame* frame = GetFrame(ev);
- FW_ASSERT(frame);
-
- if (frame->PrivActiveWindowOnMouseDown(ev, theEmbeddedMouseEvent.GetFacet(ev), TRUE))
- return TRUE;
-
- FW_CSelection* selection = frame->GetPresentation(ev)->GetSelection(ev);
- if (selection)
- selection->UpdateSelectionOnMouseDown(ev,
- theEmbeddedMouseEvent,
- theEmbeddedMouseEvent.GetEmbeddedFacet(ev),
- FALSE, // Not in active border
- FALSE); // Not in Background
-
- return FW_MEventHandler::HandleMouseDownInEmbeddedFrame(ev, theEmbeddedMouseEvent);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CView::HandleBGMouseDownInEmbeddedFrame
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_CView::HandleBGMouseDownInEmbeddedFrame(Environment* ev,
- const FW_CEmbeddedMouseEvent& theEmbeddedMouseEvent)
- {
- FW_CFrame* frame = GetFrame(ev);
- FW_ASSERT(frame);
-
- FW_CSelection* selection = frame->GetPresentation(ev)->GetSelection(ev);
- if (selection)
- selection->UpdateSelectionOnMouseDown(ev,
- theEmbeddedMouseEvent,
- theEmbeddedMouseEvent.GetEmbeddedFacet(ev),
- FALSE, // Not in active border
- TRUE); // In Background
-
- return FW_MEventHandler::HandleBGMouseDownInEmbeddedFrame(ev, theEmbeddedMouseEvent);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CView::HandleBGMouseDown
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_CView::HandleBGMouseDown(Environment* ev, const FW_CMouseEvent& theMouseEvent)
- {
- FW_CFrame* frame = GetFrame(ev);
- FW_ASSERT(frame);
-
- FW_CSelection* selection = frame->GetPresentation(ev)->GetSelection(ev);
- if (selection)
- selection->UpdateSelectionOnMouseDown(ev, theMouseEvent, NULL, FALSE, TRUE);
-
- return FW_MEventHandler::HandleBGMouseDown(ev, theMouseEvent);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CView::DoBGMouseDown
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_CView::DoBGMouseDown(Environment *ev, const FW_CMouseEvent& theMouseEvent)
- {
- FW_CFrame* frame = GetFrame(ev);
- FW_ASSERT(frame);
-
- FW_CSelection* selection = frame->GetPresentation(ev)->GetSelection(ev);
- if (selection != NULL && selection->IsMouseInDraggableItem(ev, frame, theMouseEvent, TRUE))
- return frame->Drag(ev, theMouseEvent);
-
- // return FALSE because I am not doing anything. Let the process manager do its job.
- return FALSE;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CView::HandleMouseUp
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_CView::HandleMouseUp(Environment* ev, const FW_CMouseEvent& theMouseEvent)
- {
- FW_CFrame* frame = GetFrame(ev);
- FW_ASSERT(frame);
-
- frame->ActivateFrame(ev, theMouseEvent.GetFacet(ev)); // Will test if it can be the activeframe
-
- return FW_MEventHandler::HandleMouseUp(ev, theMouseEvent);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CView::GetVisibleBounds
- //----------------------------------------------------------------------------------------
- // Returns the visible bounds of the view through all its parent (in frame coordinate)
-
- FW_CRect FW_CView::GetVisibleBounds(Environment *ev) const
- {
- FW_CView* aView = (FW_CView*)this;
- FW_CRect visibleRect;
- while (aView != NULL)
- {
- FW_CRect bounds = aView->GetBounds(ev);
- bounds.Place(FW_kFixed0, FW_kFixed0);
- aView->ViewToFrame(ev, bounds);
-
- if (aView == this)
- visibleRect = bounds;
- else
- visibleRect.Intersection(bounds);
-
- aView = aView->GetParentView(ev);
- }
-
- return visibleRect;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CView::HandleDraw
- //----------------------------------------------------------------------------------------
- // invalidShape is in frame coordinate
-
- void FW_CView::HandleDraw(Environment *ev, ODFacet* odFacet, ODShape* invalidShape)
- {
- if (fVisible) {
- // [LSD] todo: Draw high-priority adorners
-
- FW_CAcquiredODShape aqInvalidShape;
-
- // Restricted the invalidShape to the view bounds intersected with all its parents
- if (invalidShape != NULL)
- {
- aqInvalidShape = invalidShape->Copy(ev);
-
- FW_CRect visibleBounds = GetVisibleBounds(ev);
-
- FW_CAcquiredODShape tempShape = ::FW_NewODShape(ev, visibleBounds);
- aqInvalidShape->Intersect(ev, tempShape);
-
- FrameToViewContent(ev, aqInvalidShape);
- }
-
- // Draw the view
- Draw(ev, odFacet, aqInvalidShape);
-
- // Draw its subviews
- FW_CViewIterator ite(ev, this);
- for (FW_CView* subview = ite.First(ev); ite.IsNotComplete(ev); subview = ite.Next(ev))
- {
- subview->HandleDraw(ev, odFacet, invalidShape);
- }
-
- // [LSD] todo: Draw low-priority adorners
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CView::Draw
- //----------------------------------------------------------------------------------------
- // invalidShape is in content coordinate of this view
-
- void FW_CView::Draw(Environment *ev, ODFacet* odFacet, ODShape* invalidShape)
- {
- FW_UNUSED(odFacet);
- FW_UNUSED(invalidShape);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CView::Activate
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_CView::Activate(Environment* ev)
- {
- FW_Boolean result = FW_MEventHandler::Activate(ev);
-
- // [LSD] simple progagation of Activate to Subviews for now.
- FW_CViewIterator ite(ev, this);
- for (FW_CView* subview = ite.First(ev); ite.IsNotComplete(ev); subview = ite.Next(ev))
- {
- subview->Activate(ev);
- }
-
- return result;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CView::Deactivate
- //----------------------------------------------------------------------------------------
-
- void FW_CView::Deactivate(Environment* ev)
- {
- FW_MEventHandler::Deactivate(ev);
-
- // progagates Deactivate to Subviews
- FW_CViewIterator ite(ev, this);
- for (FW_CView* subview = ite.First(ev); ite.IsNotComplete(ev); subview = ite.Next(ev))
- {
- subview->Deactivate(ev);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CView::SetVisible
- //----------------------------------------------------------------------------------------
-
- void FW_CView::SetVisible(Environment* ev, FW_Boolean visible, FW_Boolean propagate)
- {
- // Not allowed to make the Frame invisible!
- FW_ASSERT(IsFrame(ev) == FALSE || visible == TRUE);
-
- fVisible = visible;
-
- // Activate/Deactivate event handler
- if (visible) {
- FW_MEventHandler::Activate(ev);
- }
- else {
- FW_MEventHandler::Deactivate(ev);
- }
-
- // propagates to subviews
- if (propagate) {
- FW_CViewIterator ite(ev, this);
- for (FW_CView* subview = ite.First(ev); ite.IsNotComplete(ev); subview = ite.Next(ev))
- {
- subview->SetVisible(ev, visible, TRUE);
- }
- }
- }
-
- //========================================================================================
- // CLASS FW_CViewContext
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_CViewContext::FW_CViewContext
- //----------------------------------------------------------------------------------------
- // invalidShape should be in content coordinate of the view
-
- FW_CViewContext::FW_CViewContext(Environment* ev, FW_CView *view, ODFacet* odFacet, ODShape* invalidShape) :
- FW_CGraphicContext(ev),
- fView(view),
- fFacet(odFacet),
- fTransform(NULL)
- {
- fTransform = FW_CopyAndRelease(ev, view->AcquireViewContentToFrameTransform(ev));
-
- // compute fTransform to convert view to canvas coordinates
- FW_CAcquiredODTransform aqFrameTransform = fFacet->AcquireFrameTransform(ev, NULL);
- fTransform->PostCompose(ev, aqFrameTransform);
-
- // Make a copy of the aggregate clip shape
- FW_CAcquiredODShape aqClipShape = FW_CopyAndRelease(ev, odFacet->AcquireAggregateClipShape(ev, NULL));
-
- // Intersect it with the visible part of the view
- {
- FW_CRect visibleBounds = view->GetVisibleBounds(ev);
- FW_CAcquiredODShape visibleShape = ::FW_NewODShape(ev, visibleBounds);
- aqClipShape->Intersect(ev, visibleShape);
- }
-
- // convert it to view content coordinates
- view->FrameToViewContent(ev, aqClipShape);
-
- // Intersect it with the invalidShape (already in view content coordinates)
- if (invalidShape != NULL)
- aqClipShape->Intersect(ev, invalidShape);
-
- InitGraphicContext(FW_CFacetPartInfo::GetFacetGraphicDevice(ev, fFacet),
- fTransform,
- aqClipShape);
-
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CViewContext::~FW_CViewContext
- //----------------------------------------------------------------------------------------
-
- FW_CViewContext::~FW_CViewContext()
- {
- FW_START_DESTRUCTOR
-
- if (fTransform)
- fTransform->Release(somGetGlobalEnvironment());
- }
-
- //========================================================================================
- // CLASS FW_CViewIterator
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_CViewIterator::FW_CViewIterator
- //----------------------------------------------------------------------------------------
-
- FW_CViewIterator::FW_CViewIterator(Environment* ev, const FW_CView *container) :
- fIterator(NULL)
- {
- if (container->fSubViews)
- fIterator = new FW_COrderedCollectionIterator(container->fSubViews);
-
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CViewIterator::~FW_CViewIterator
- //----------------------------------------------------------------------------------------
-
- FW_CViewIterator::~FW_CViewIterator()
- {
- FW_START_DESTRUCTOR
-
- delete fIterator;
- }
-